package cn.com.digitalnet.ad.service;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Row;

import com.google.common.collect.Maps;

import cn.com.digitalnet.ad.base.CrudService;
import cn.com.digitalnet.ad.entity.SelfConstruction;
import cn.com.digitalnet.ad.entity.User;
import cn.com.digitalnet.ad.repository.mybatis.CrudMao;
import cn.com.digitalnet.ad.repository.mybatis.SelfConstructionMao;
import cn.com.digitalnet.ad.util.FileUploader;
import cn.com.digitalnet.ad.util.PropertiesHolder;

@Service
@Transactional
public class SelfConstructionService extends CrudService<SelfConstruction> {

	@Autowired
	private SelfConstructionMao mao;
	@Autowired
	PropertiesHolder holder;
	@Autowired
	private FileUploader uploader;

	@Override
	protected CrudMao<SelfConstruction> mao() {
		// TODO Auto-generated method stub
		return mao;
	}

	
	
	
	public void uploadAttach(HttpServletRequest request, MultipartFile[] files,
			SelfConstruction e) {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder(e.getFilename());
		StringBuilder uuidName= new StringBuilder(e.getAttachment());
		for (int i = 0; i < files.length; i++) {
			MultipartFile file = files[i];
			String ext = StringUtils.substringAfterLast(
					file.getOriginalFilename(), ".");
			String realName=file.getOriginalFilename();
			
			if (!StringUtils.isEmpty(ext)) {
				sb.append(realName+",");
				String name = uploader.uploadAttac(files[i]);
				uuidName.append(name+",");
			}

		}
		
		e.setAttachment(uuidName.toString());
		e.setFilename(sb.toString());

	}
}
